
var Choice = function(obj) { // { id : asdfasdf, name : asdfasdf}
	this.class = 'Choice';
	obj = obj || {};
	
	this.id = obj.id || "";
	this.name = obj.name || "";
	this.index = obj.index || 0;
	
	return this;
};

Choice.prototype.toXML = function() {
	var xml = '<addChoiceRequest id="' + this.id + '" number="' + this.index + '" choice="' + this.name + '"/>';
	
	return xml;
};

Choice.prototype.fromXML = function(xml) {
	// <addChoiceResponse id="sdjklakj3s" number="3" choice="TGIF's"/>
	xml = xml.replace(/\r\n|\n/g, ''); // remove line breaks
	
	var idMatch = xml.match(/id="(\S+)"/i) || [];
	this.id = idMatch[1] || "";
	
	var nameMatch = xml.match(/choice="(\S+)"/i) || [];
	this.name = nameMatch[1] || "";
	
	var indexMatch = xml.match(/number="(\d+)"/i) || [];
	this.index = indexMatch[1] || 0;
	
	return this;
};

module.exports = Choice;
